var express = require('express');
var mysql = require('mysql');
var path = require('path');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.static(path.join(__dirname, 'static')));
var pool = mysql.createPool({
  host     : '192.168.115.119',
  user     : 'root',
  password : 'root',
  database : 'smartwork'
});

app.get('/',function(req,res){
	res.render('login');
});

//user list
app.post('/user/list',function(req,res){
	pool.getConnection(function(err,connection){
		connection.query('select name from node_user',function(err,rows,fields){
			if(err) throw err
				res.render('user.jade',{title:'SysUser List',users:rows});
		});
		connection.release();
	});
});
//to create user
app.get('/create',function(req,res){
	res.render('create.jade',{title:'Create a new user'});
});
//do create user
app.post('/create',function(req,res){
	pool.getConnection(function(err,connection){
		connection.query('insert into node_user set ?',{id:'10000',name:'node'},function(err,fields){
			if(err) throw err
		});
		connection.release();
	});
});
//to edit user
app.get('/update/:id',function(req,res){

});	
//do edit
//do delete
var server = app.listen(3000,function(){
	console.log('server is start');
})